package com.book.service.impl;

import com.book.dao.StudentMapper;
import com.book.entity.Student;
import com.book.service.StudentService;
import com.book.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/*
 **@Author:youpeng
 **Created on 2022/4/25
 */
public class StudentServiceImpl implements StudentService {
    @Override
    public List<Student> getStudentList() {
        try(SqlSession sqlSession = MybatisUtil.getSession()){
            StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
            return studentMapper.getStudentList();
        }
    }

    @Override
    public int addStudent(String name, String sex, String grade) {
        try(SqlSession sqlSession = MybatisUtil.getSession()){
            StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
            return studentMapper.addStudent(name, sex, grade);
        }
    }

    @Override
    public int deleteStudentBySid(int sid) {
        try(SqlSession sqlSession = MybatisUtil.getSession()){
            StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
            return studentMapper.deleteStudentBySid(sid);
        }
    }

    @Override
    public List<Student> getStudentListLike(String msg) {
        try(SqlSession sqlSession = MybatisUtil.getSession()){
            StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
            return studentMapper.getStudentListLike(msg);
        }
    }

    @Override
    public int updateStudent(Student student) {
        try(SqlSession sqlSession = MybatisUtil.getSession()){
            StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
            return studentMapper.updateStudent(student);
        }
    }
}
